package com.clgk.wechatmall.freemarker;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

public class ColumnVo {

	
	private String columnname;
	private String firstUpName;
	private String lownerame;
	
	private String datatype;
	/**
	 * get返回 Long、Integer、String等
	 */
	private String datatypetojava;
	
	private String columncomment;
	
	private String columntype;
	
	private String columnkey;

	public String getColumnname() {
		return columnname;
	}

	public void setColumnname(String columnname) {
		this.columnname = columnname;
	}

	public String getDatatype() {
		return this.datatype;
	}

	public void setDatatype(String datatype) {
		this.datatype = datatype;
	}

	public String getColumncomment() {
		return columncomment;
	}

	public void setColumncomment(String columncomment) {
		this.columncomment = columncomment;
	}

	public String getColumntype() {
		return columntype;
	}

	public void setColumntype(String columntype) {
		this.columntype = columntype;
	}

	public String getColumnkey() {
		return columnkey;
	}

	public void setColumnkey(String columnkey) {
		this.columnkey = columnkey;
	}

	public String getDatatypetojava() {
		if(StringUtils.isBlank(this.datatype)){
			return "String";
		}
		if(StringUtils.equalsIgnoreCase(this.datatype, "bigint")
				|| StringUtils.equalsIgnoreCase(this.datatype, "int")){
			if(StringUtils.isBlank(this.columntype)){
				return "Integer";
			}
			Pattern p = Pattern.compile("\\d+");
			Matcher matcher = p.matcher(this.columntype);
			if(matcher.find()){
				String str = matcher.group();
				if(StringUtils.length(str) < 2){
					return "Integer";
				}
				return "Long";
			}
			return "Integer";
		}
		if(StringUtils.equalsIgnoreCase(this.datatype, "float")
				|| StringUtils.equalsIgnoreCase(this.datatype, "double")){
			return "Float";
		}
		return "String";
	}

	public String getFirstUpName() {
		if(null != this.firstUpName){
			return firstUpName;
		}
		if(StringUtils.isBlank(this.columnname)){
			this.firstUpName = "";
		}else{
			this.firstUpName = StringUtils.lowerCase(this.columnname);
			this.firstUpName = this.firstUpName.substring(0,1).toUpperCase() + this.firstUpName.substring(1);
		}
		return firstUpName;
	}

	public String getLownerame() {
		return this.columnname.toLowerCase();
	}
}
